/*
 * ============================================================================
 * Copyright Notice!
 * ----------------------------------------------------------------------------
 * This file contains proprietary and confidential information belonging to the
 * group of people involvled in developing this project.  Reproduction, disclosure 
 * or use without specific written authorization from project stake holders is 
 * prohibited. Please refer the readme.txt in project installation folder for more
 * specific contacts
 *
 * All rights reserved.
 * ============================================================================
 */
package edu.uwm.universitydb.dao.professor;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import edu.uwm.universitydb.model.Professor;

/**
 * <code>GetProjectCoInvestigatorsCommand</type>
 * 
 * @author Shyam Nair
 */
public class GetProjectCoInvestigatorsCommand extends SearchProfessorCommandBase<List<Professor>>
{
    private static final String SQL_QUERY =
        ",university.co_investigate where university.co_investigate.pno = ? and "
            + "university.co_investigate.prof_ssn = p.prof_ssn and "
            + "p.prof_ssn = university.works.prof_ssn and "
            + "university.works.dno = d.dno;";

    /** attribute holding the ssn */
    private final Integer mPid;

    /**
     * 
     * @param pid
     */
    public GetProjectCoInvestigatorsCommand(final int id)
    {
        mPid = id;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DataFetchCommand#processResult(java.sql.ResultSet)
     */
    @Override
    public List<Professor> processResult(final ResultSet result) throws SQLException
    {
        final List<Professor> professorList = new ArrayList<Professor>();
        while (result.next())
        {
            final Professor professor = getProfessor(result);
            professorList.add(professor);
        }
        return professorList;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#getSQL()
     */
    @Override
    public String getSQL()
    {
        return SELECT_SQL + SQL_QUERY;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#setParameters(java.sql.PreparedStatement)
     */
    @Override
    public void setParameters(final PreparedStatement pStmt) throws SQLException
    {
        pStmt.setInt(1, mPid);
    }
}
/*
 * ============================================================================
 * Change History
 * ----------------------------------------------------------------------------
 * Apr 30, 2014   Shyam Nair
 * File created
 * ----------------------------------------------------------------------------
 */